package com.example.springboot4.system.config;

import io.jsonwebtoken.lang.Assert;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * Security配置参数
 *
 * @author 宋义州
 * @since 2024/1/15 10:00
 */
@Data
@Component
@ConfigurationProperties(ignoreInvalidFields = true, prefix = "token")
public class SecurityConfigProperties implements InitializingBean {

    /**
     * 请求头token名称
     */
    private String header;

    /**
     * jwt 密钥
     */
    private String secret;

    /**
     * jwt 有效期（单位 分钟）
     */
    private int expireTime;

    @Override
    public void afterPropertiesSet() {
        Assert.hasText(this.secret, "jwt-secret must be set");
        Assert.notNull(this.expireTime, "jwt-expiration-ms must be set");
        Assert.notNull(this.header, "jwt-token-name must be set");
    }
}
